package com.foreknow.elm.controller;


import com.foreknow.elm.po.Orders;
import com.foreknow.elm.service.impl.OrdersServiceImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class OrdersController {
    // 获取前台请求参数 OrdersController/createOrder?userId=?&businessId=?&daId=?&orderTotal=?
    public Object createOrder(HttpServletRequest request){
        OrdersServiceImpl ordersService = new OrdersServiceImpl();
        String userId = request.getParameter("userId");
        Integer businessId = Integer.parseInt(request.getParameter("businessId"));
        Integer daId = Integer.parseInt(request.getParameter("daId"));
        String orderTotal = request.getParameter("orderTotal");
        int orderId = ordersService.saveOrder(userId, businessId, daId, orderTotal);
        return orderId;
    }

     // 获取前台请求参数 OrdersController/getOrdersById?orderId=1
    public Object getOrdersById(HttpServletRequest request){
        OrdersServiceImpl ordersService = new OrdersServiceImpl();
        Integer orderId = Integer.parseInt(request.getParameter("orderId"));
        Orders orders = ordersService.getOrdersById(orderId);
        return orders;
    }

    public Object listOrdersByUserId(HttpServletRequest request){
        // 获取前台请求参数 /OrdersController/listOrdersByUserId?userId=11111111111
        OrdersServiceImpl ordersService = new OrdersServiceImpl();
        String userId = request.getParameter("userId");
        List<Orders> list = ordersService.listOrdersByUserId(userId);
        return list;
    }
}
